package gopi.labs.cloudspace.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpRequest {

	private final String USER_AGENT = "Mozilla/5.0";

	public static void main(String[] args) throws Exception {

		HttpRequest http = new HttpRequest();

		http.sendGet();

	}

	// HTTP GET request
	private void sendGet() throws Exception {

		String url = "http://54.204.33.197:8001/DRUG_ADHERE_STREAM";

		URL obj = new URL(url);
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();

		// optional default is GET
		con.setRequestMethod("GET");

		con.setRequestProperty("User-Agent", USER_AGENT);
		con.setDoOutput(true);
		String str = "{\"datetime\":\"11-DEC-2013\", \"CUSTOMERID\":\"CTD0000148337\", \"med_dt\":\"11/28/2014\", \"taken\":\"Not Sure\"}";
		con.getOutputStream().write(str.getBytes());
		// add request header
		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'GET' request to URL : " + url);
		System.out.println("Response Code : " + responseCode);

		BufferedReader in = new BufferedReader(new InputStreamReader(
				con.getInputStream()));
		String inputLine;
		StringBuffer response = new StringBuffer();

		while ((inputLine = in.readLine()) != null) {
			response.append(inputLine);
		}
		in.close();

		// print result
		System.out.println(response.toString());

	}

}